Skip to content

feat(config): auto-detect supported config files in the working directory#901

Open
AysajanE wants to merge 3 commits into
nodejs:mainfrom
AysajanE:northset/M-012
Open

feat(config): auto-detect supported config files in the working directory#901
AysajanE wants to merge 3 commits into
nodejs:mainfrom
AysajanE:northset/M-012

Conversation

@AysajanE

Copy link
Copy Markdown

Problem

doc-kit generate only loads configuration when --config-file is passed explicitly — loadConfigFile returns {} otherwise. As raised in #897, most config-driven tools also detect a conventional config file automatically, so a valid doc-kit.config.mjs sitting in the project root is silently ignored today. That is an easy footgun for anyone who assumes the file is picked up.

Change

  • In createRunConfiguration, when no --config-file is provided, auto-detect a doc-kit.config.mjs in the current working directory and load it through the existing loader. An explicit --config-file still takes precedence, and when no file is present the configuration falls back to empty — unchanged behavior. No new dependency; a tight happy path, as the issue suggests.
  • Add unit tests covering auto-detection, explicit-path precedence, and the no-file fallback.

Checks (Node 22)

  • node --test --experimental-test-module-mocks src/utils/configuration/__tests__/index.test.mjs — 17 passing, including the new cases.

Fixes #897


Disclosure: this change was prepared with AI assistance and reviewed by me before submitting.
I ran the check(s) above in a network-isolated container and published a signed, re-runnable
record of that run, verifiable via GitHub artifact attestation:
https://northset-oss.github.io/verification-pilot/. Contributor self-run, not a maintainer verification.

@AysajanE
AysajanE requested a review from a team as a code owner July 12, 2026 22:22
@vercel

vercel Bot commented Jul 12, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
api-docs-tooling Ready Ready Preview Jul 19, 2026 9:19pm

Request Review

@cursor

cursor Bot commented Jul 12, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
CLI configuration resolution only; explicit --config-file is unchanged and behavior falls back to {} when no file is found.

Overview
When --config-file is not passed, createRunConfiguration now uses cosmiconfig (doc-kit module name) to search the working directory for a config file and merge its config object. Explicit --config-file still goes through loadConfigFile / importFromURL and skips cosmiconfig.

Adds cosmiconfig as a runtime dependency and extends configuration unit tests for auto-discovery, explicit-path precedence, and the empty-config fallback when search finds nothing.

Reviewed by Cursor Bugbot for commit 4c8e448. Bugbot is set up for automated code reviews on this repo. Configure here.

Comment thread .changeset/quiet-dingos-detect.md Outdated
Comment thread src/utils/configuration/index.mjs Outdated

@AugustinMauroy AugustinMauroy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding blocker since feature isn't correctly covered.

thanks @AysajanE for you effort here

@AysajanE AysajanE changed the title feat(config): auto-detect doc-kit.config.mjs in the working directory feat(config): auto-detect supported config files in the working directory Jul 15, 2026
@AysajanE

Copy link
Copy Markdown
Author

Thanks for the specific direction, @AugustinMauroy and @avivkeller. I have updated and rebased the branch to cover the full supported configuration-file set.

When --config-file is omitted, discovery now checks this exact priority order:

  1. doc-kit.config.js
  2. doc-kit.config.cjs
  3. doc-kit.config.mjs
  4. doc-kit.config.ts
  5. doc-kit.config.cts
  6. doc-kit.config.mts

The first existing file wins. An explicit configFile still bypasses discovery, JSON is not included because it is unsupported, and the no-file behavior remains unchanged.

Coverage now includes:

  • all six discovered filenames;
  • exact probe order and first-match priority;
  • explicit-path precedence;
  • no-file fallback;
  • native loading for TypeScript, CommonJS TypeScript, and ES module TypeScript configurations.

Local verification on current upstream main b9750dc:

  • focused configuration and loader tests: 34 passed
  • full test suite: 529 passed, 0 failed
  • lint: 0 errors; 2 pre-existing unrelated warnings
  • format check: passed
  • diff check: passed

I also checked the still-open dynamic-configuration PR #905. It touches the same configuration area but implements dynamic default values, so there is no semantic overlap with this file-discovery correction at present.

The updated head is 662687f. Could you please take another look when CI is ready?

@avivkeller

Copy link
Copy Markdown
Member

I feel like a dep like cosmiconfig does this for us?

@avivkeller avivkeller closed this Jul 17, 2026
@avivkeller avivkeller reopened this Jul 18, 2026
@avivkeller

Copy link
Copy Markdown
Member

Didn't mean to close! Feel free to iterate based on my feedback

@AysajanE

AysajanE commented Jul 18, 2026

Copy link
Copy Markdown
Author

Thanks — that makes sense. I have reworked the revision locally to use cosmiconfig for discovery instead of maintaining the file-probing logic ourselves. The explorer is configured for the current working directory and the agreed six doc-kit.config.* names, in priority order; an explicit --config-file still bypasses discovery, and the existing loader remains responsible for JavaScript and TypeScript module loading.

Local verification is green: focused configuration tests 17/17, full suite 527/527, six-extension plus priority smoke check passed, lint has 0 errors (2 pre-existing unrelated warnings), and formatting passed. I have not updated the PR head yet.

@avivkeller

avivkeller commented Jul 18, 2026

Copy link
Copy Markdown
Member

Can you push those changes?

@AysajanE

Copy link
Copy Markdown
Author

Thanks — I’ve pushed the cosmiconfig revision in ed0755a.

Configuration discovery is now scoped to the current working directory and uses the agreed priority order for doc-kit.config.js, .cjs, .mjs, .ts, .cts, and .mts. An explicit --config-file still bypasses discovery.

Validation after the update:

  • focused configuration tests: 17/17 passed
  • full test suite: 527/527 passed
  • lint: 0 errors (2 pre-existing unrelated warnings)
  • formatting: passed
  • real-file smoke test: all six extensions and first-match priority passed

Please take another look when convenient.

@codecov

codecov Bot commented Jul 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.17%. Comparing base (4534824) to head (ed0755a).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #901      +/-   ##
==========================================
- Coverage   86.17%   85.17%   -1.01%     
==========================================
  Files         188      192       +4     
  Lines       17146    17575     +429     
  Branches     1540     1565      +25     
==========================================
+ Hits        14776    14969     +193     
- Misses       2363     2599     +236     
  Partials        7        7              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread src/utils/configuration/index.mjs Outdated
Comment on lines +160 to +164
await cosmiconfig('doc-kit', {
searchPlaces: CONFIG_FILE_NAMES,
loaders: CONFIG_LOADERS,
searchStrategy: 'none',
}).search(process.cwd())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this so complex?

Can we not just:

const explorer = cosmiconfig('doc-kit');
const result = await explorer.search();

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right that search() already starts from process.cwd() and defaults to a non-traversing search, so the explicit working directory and searchStrategy are redundant.

The additional searchPlaces and loaders were preserving the six filenames requested in the earlier review: doc-kit.config.js, .cjs, .mjs, .ts, .cts, and .mts, with a defined priority. In particular, cosmiconfig defaults do not discover .cts or .mts, and using its defaults would also broaden discovery to package/rc/JSON/YAML conventions.

I can simplify this to cosmiconfig("doc-kit").search() if that earlier six-extension requirement is no longer desired. That would intentionally drop automatic .cts/.mts discovery and follow the standard cosmiconfig conventions instead, while explicit --config-file paths would remain unchanged. Could you confirm which behavior you prefer?

@avivkeller avivkeller Jul 19, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer that you simplified this, as I had requested, regardless of MTS/TS support.

I'd also prefer to I spoke to a human :-)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. I am reading every comment here as the real person Aysajan Eziz, as I am typing this manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consideration: detect doc-kit.config.mjs automatically

3 participants